//页面加载完成
$(function () {

    var  salary_datagrid =  $("#salary_datagrid");

    //初始员工列表界面
    salary_datagrid.datagrid({
        fit: true,
        fitColumns: true,
        striped: true,
        url: '/salary/list',
        rownumbers: true,
        pagination: true,
        singleSelect:true,
        columns: [[
            {field: 'id', hidden:true},
            {field: 'department', title: '部门',width: 100, align: 'center',formatter:dpeartmentFormatter},
            {field: 'tel', title: '电话',width: 100,formatter:telFormatter},
            {field: 'userName', title: '姓名',width: 100, align: 'center',formatter:userNameFormatter},
            {field: 'email', title: '邮箱',width: 100, align: 'center',formatter:emailFormatter},
            {field: 'inputTime', title: '入职时间',width: 100, align: 'center',formatter:inputTimeFormatter},
            {field: 'baseSalary', title: '基本工资',width: 100, align: 'center'},
            {field: 'bonus', title: '奖金',width: 100, align: 'center'},
            {field: 'yearMonth', title: '年薪',width: 100, align: 'center'},
            {field: 'remark',title: '查看', width: 100, align: 'center',formatter:function(value, row, index){
                return '<a href="javascript:;" class="easyui-linkbutton" onclick="look()">查看明细</a>';
            },
            }
        ]],
        toolbar: "#salary_toolbar"
    });
    //将方法绑定到对象中
    var cmdObj = {
        searchForAtt:function () {
            var beginDate = $("#beginDate").val();
            var endDate = $("#endDate").val();
            var keyword= $("#keyword").val();
            var deptId= $("#deptId").val();
            //再次加载数据
            salary_datagrid.datagrid("load",{deptId:deptId,keyword:keyword,beginDate:beginDate,endDate:endDate});
        },
    }
    //使用js来绑定事件  使用了属性过滤器来完成该操作
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        //调用方法
        cmdObj[cmd]();
    });
    //end
})
//部门格式化操作
function dpeartmentFormatter(value, row, index) {

    return value ? row.department.name : "";

}
//员工姓名格式化操作
function telFormatter(value, row, index) {

    return row.employee ? row.employee.tel : "";

}
function userNameFormatter(value, row, index) {
    return row.employee ? row.employee.userName : "";

}
function emailFormatter(value, row, index) {

    return row.employee ? row.employee.email : "";

}
function  inputTimeFormatter(value, row, index) {

    return row.employee ? row.employee.inputTime : "";

}
function look() {
    $.messager.confirm("提示","正在下载资源,请稍后.....","error");
}



